function! s:bufferline() abort
    if !exists('g:loaded_bufferline')
        try
            packadd vim-bufferline
        catch /.*/
            echoerr v:exception
        endtry
    endif
    if exists('g:loaded_bufferline')
        let g:bufferline_active_buffer_left = '['
        let g:bufferline_active_buffer_right = ']'
        let g:bufferline_modified = '+'
        let g:bufferline_show_bufnr = 1
        " default, no rotate, no scrolling{{{
        " let g:bufferline_rotate = 0
        " scrolling with fixed current buffer position
        let g:bufferline_rotate = 1
        " scrolling without fixed current buffer position
        " let g:bufferline_rotate = 2
        " }}}
        " only valid when `g:bufferline_rotate` is set to 1:{{{
        let g:bufferline_fixed_index =  0 "always first
        let g:bufferline_fixed_index =  1 "always second (default)
        let g:bufferline_fixed_index = -1 "always last
        " }}}
        let g:bufferline_inactive_highlight = 'StatusLineNC'
        let g:bufferline_active_highlight = 'StatusLine'
        let g:bufferline_solo_highlight = 1
        let g:bufferline_pathshorten = 1
        let g:bufferline_echo = 1
        " let g:bufferline_echo = 0
        autocmd VimEnter *
                    \ let &statusline='%{bufferline#refresh_status()}'
                    \ .bufferline#get_status_string()
    endif
endfunction

function! s:bufexplorer() abort
    if !exists("g:bufexplorer_version") 
        try
            packadd bufexplorer
        catch /.*/
            echoerr v:exception
        endtry
    endif
    if exists("g:bufexplorer_version") && g:bufexplorer_version
        let g:buffer_keymap = get(g:, "buffer_keymap", { "name": "+buffer" })
        let g:buffer_keymap.e = [':BufExplorer', 'explore']
    endif
endfunction

function! api#buffer#init() abort
    call s:bufferline()
    call s:bufexplorer()
    call api#startify#init()
endfunction
